import { createMQTT } from '../hooks/vue-mqtt';
import { randomId } from './index';
import config from '../services/config.js';

const clientId = randomId('mqtt_', 1000);

// 测试
//默认通信协议
let protocol = "wss"
//微信通信协议为wxs
//#ifdef MP-WEIXIN
protocol = "wxs"
//#endif

const mqttUrl = config.CAIDAN_MQTT_HOST;
const port = config.CAIDAN_MQTT_PORT;

const mqtt = createMQTT(`${protocol}://${mqttUrl}`, {
	port,
	clientId: clientId,
	clean: true,
	connectTimeout: 4000,
	username: config.CAIDAN_MQTT_USERNAME,
	password: config.CAIDAN_MQTT_PASSWORD,
	keepalive: 30,
});

export default mqtt;
